<template>
    <Datalist 
    :cate="cate"
     :cols="cols" 
     :excelHeader="excelHeader"
     skipExcelNumber="2"
     :name="name"
     :groupCheck = "groupCheck" 
     
    />
</template>
<script>
import Datalist from "@/components/DataList";
import { getUser } from "@/utils/auth";
import {addJxgl,deleteJxgl,updateJxgl,getJxgl,bulkAddJxgl } from "@/api/教学与学生管理文件.js"
import { get机构设置,update机构设置,delete机构设置,add机构设置 } from '@/api/机构设置.js'
import linq from "linq";
import {findComponent} from "@/utils/ui";
export default {
    components: {
        Datalist
    },
 
    data() {
        return {
            cate: "A8-1教学与学生管理文件表",
             name:'8.1 教学与学生管理文件',
            excelHeader:{B3:"文件名称(全称)及文号",C3:"发布日期（年月）",D3:"发布部门",E3:"变更情况（新增、修改、取消）",F3:"变更日期（年月）",G3:"负责部门"},
            cols: [
            
                { label: "文件名称(全称)及文号", prop: "GWBT"},
                { label: "发布日期(年月)", prop: "FWRQ"},
                { label: "发布部门", prop: "FBBMMC"},
                { label: "变更情况(新增、修改、取消)", prop: "XZ_BGQK"},
                { label: "变更日期", prop: "BGRQ"},
                { label: "负责部门", prop: "FZBMMC"},
                
            ],
            groupCheck:[{dada:["XZ_BGQK","BGRQ"],desc:'请完善变更情况和变更日期'}]
        }
    },
    methods:{
        getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]= "文件数:"+linq.from(list).count("$.GWBT");
         sums[8]= "发布部门数："+linq.from(list).distinct("$.FBBMMC").count();
         sums[11]= "负责部门："+linq.from(list).distinct("$.FZBMMC").count();
         sums[9]= "新增:"+linq.from(list).where("$.XZ_BGQK=='新增'").count();
         sums[9]+= ",修改:"+linq.from(list).where("$.XZ_BGQK=='修改'").count();
         sums[9]+= ",取消:"+linq.from(list).where("$.XZ_BGQK=='取消'").count();
        sums[12]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
        sums[12] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
        sums[12] += ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
       return sums;
      //
    },
        check(array,list) {
             return new Promise(async (resolve,reject)=>{
                  try{
                  var user = getUser();
                  var 部门 = await get机构设置(user.XXID,user.CJPC); 
        
                  var err = linq.from(array).select("$.FBBMMC").except(linq.from(部门).select("$.BMMC").toArray()).toArray();
                  linq.from(array).where(e=>err.indexOf(e.FBBMMC) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"不存在相对应的部门");
             
              resolve();
          }catch(e){
            reject(e);
           }
             
             })

    },
    async onDlgCreated(){
     
      var 部门 = await get机构设置(this.$root.user.XXID,this.$root.user.CJPC);
      var dd= findComponent(this, "FBBMMC");
      var cc= findComponent(this, "FZBMMC");
      var data = linq.from(部门).select("{...$,value:$.BMMC}").distinct("$.value").toArray();
      dd.$attrs.items = data;
      cc.$attrs.items = data;
    },
    async  bulkAdd(array){
       await  bulkAddJxgl({Jxgl:array});
    },
    async fetchData() {
     var user = getUser();
      var datas = await getJxgl(user.XXID,user.CJPC);
      return datas;
    },
     onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          var model = await addJxgl(temp);
          resolve(model);
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateJxgl(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteJxgl(temp);
          resolve();
      })
    }
        
    }
     
}
</script>
<style>
</style>


